package com.fancy.learncenter.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.fancy.learncenter.activity.GoodsDetailActivity;
import com.fancy.learncenter.adapter.base.CommonRecycleViewAdapter;
import com.fancy.learncenter.adapter.base.CustomViewHold;
import com.fancy.learncenter.bean.GoodsDataBean;
import com.superservice.lya.R;

import java.util.ArrayList;


/**
 * Created by hyy on 2018/4/25.
 */

public class MyReleaseGoodsAdapter extends CommonRecycleViewAdapter<GoodsDataBean> {
    public MyReleaseGoodsAdapter(Context mContext, ArrayList<GoodsDataBean> itemDatas) {
        super(mContext, R.layout.activity_my_releasegoods, itemDatas);
    }

    @Override
    public void bindView(CustomViewHold customViewHold, final GoodsDataBean item, final int position) {

        TextView name = customViewHold.getView(R.id.name);
        name.setText(item.getTitle());

        TextView price = customViewHold.getView(R.id.price);
        price.setText("¥" + item.getPrice());

        SimpleDraweeView simpleDraweeView = customViewHold.getView(R.id.simpleDraweeView);
        simpleDraweeView.setImageURI(item.getMain_img());

        customViewHold.getRoorView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, GoodsDetailActivity.class);
                intent.putExtra("GoodsDataBean", item.getId() + "");
                mContext.startActivity(intent);
            }
        });

        ImageView delete = customViewHold.getView(R.id.delete);
        delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onClickCallBack.deleteGoods(position, item);
            }
        });

        TextView edit = customViewHold.getView(R.id.edit);
        edit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onClickCallBack.editGoods(item);
            }
        });


        if (item.getIs_publish().equals("0")) {
            edit.setText("我要上架");
            edit.setBackgroundResource(R.drawable.follow_bg);
        } else {
            edit.setText("我要下架");
            edit.setBackgroundResource(R.drawable.follow_cancer_bg);
        }


    }

    private OnClickCallBack onClickCallBack;

    public OnClickCallBack getOnClickCallBack() {
        return onClickCallBack;
    }

    public void setOnClickCallBack(OnClickCallBack onClickCallBack) {
        this.onClickCallBack = onClickCallBack;
    }

    public interface OnClickCallBack {
        abstract void deleteGoods(int position, GoodsDataBean item);

        abstract void editGoods(GoodsDataBean item);
    }
}
